from PySide6.QtWidgets import QApplication
from PySide6.QtWidgets import QPushButton,QWidget,QDialog,QHBoxLayout,QPushButton
from PySide6.QtCore import QPropertyAnimation,QPoint,QSize

class MyButtonWidget(QWidget):
    def __init__(self):
        super(MyButtonWidget, self).__init__()
        self.button = QPushButton("Animated Button", self)
        self.anim = QPropertyAnimation(self.button, b"pos")
        self.anim.setDuration(10000)
        self.anim.setStartValue(QPoint(0, 0))
        self.anim.setEndValue(QPoint(100, 250))
        self.anim.start()

class MyDialog(QDialog):
    def __init__(self):
        super(MyDialog, self).__init__()
        self.v=QHBoxLayout(self)
        self.b=QPushButton("add",self)
        self.v.addWidget(self.b)
        # self.button = QPushButton("Animated Button", self)
        # self.anim = QPropertyAnimation(self.button, b"pos")
        # self.anim.setDuration(10000)
        # self.anim.setStartValue(QPoint(0, 0))
        # self.anim.setEndValue(QPoint(100, 250))
        # self.anim.start()
        self.b.clicked.connect(self.bclick)
    def bclick(self):
        self.button = QPushButton("Animated Button", self)
        self.button.resize(QSize(200, 100))
        self.button.show()
        self.anim = QPropertyAnimation(self.button, b"pos")
        self.anim.setDuration(5000)
        self.anim.setStartValue(QPoint(100,100))
        self.anim.setEndValue(QPoint(100, 200))
        self.anim.stateChanged.connect(self.v_change)
        self.anim.start()
    def v_change(self,v):
        if v==QPropertyAnimation.State.Stopped:
            if self.button !=None:
                self.button.deleteLater()
                self.button=None
if __name__ == "__main__":

    a = QApplication([])
    d=MyDialog()
    d.resize(QSize(800, 600))
    d.show()
    # buttonAnimWidget = MyButtonWidget()
    # buttonAnimWidget.resize(QSize(800, 600))
    # buttonAnimWidget.show()
    a.exec()